package com.codeduck.kafka.kafka.properties;

import com.codeduck.kafka.util.NetworkUtils;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Properties;
import java.util.UUID;

/**
 * @auther Mahone Yan
 * @date 2023/5/7
 */
public enum ProducerProperties {
    INSTANCE;
    private static final String CLIENT_ID_PROPS = "client.id";
    private Properties props = new Properties();

    ProducerProperties() {
        InputStream inputStream = ProducerProperties.class.getClassLoader().getResourceAsStream("kafka/producer.properties");
        try {
            props.load(inputStream);
            String val = (String) props.get(CLIENT_ID_PROPS);
            props.put(CLIENT_ID_PROPS, val + "_" + NetworkUtils.getIP() + "_" + UUID.randomUUID().toString().replace("-", "_").substring(0, 10));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static Properties getProperties() {
        return ProducerProperties.INSTANCE.props;
    }
}
